package com.stone.java8;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.stone.java8.baselam.Lam01;


/**
 * desc   :
 * author : stone
 * email  : aa86799@163.com
 * time   : 06/03/2017 19 54
 */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        Button btn = (Button) findViewById(R.id.btnClick);
        btn.setOnClickListener(Lam01.getOnClickListener());
        btn.setOnClickListener(Lam01.getOnClickListener("san"));

        Lam01.testBaseLambda();

//        Lam01.testTypeInfer(); //retrolambda 支持不好
//        Lam01.testPredicate(10);

        print(() -> "张三");

        print(() -> {
            System.out.println("干活了");
            return "李四";
        });

//        Button button = null;
//        button.setOnTouchListener((view, event)-> {
//            if (event.getAction() == MotionEvent.ACTION_DOWN) {
//                //do sth.
//                return true;
//            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
//                //do sth.
//                return true;
//            }
//            return super.onTouchEvent(event);
//        });
//
//        button.setOnTouchListener(this::handleEvent);

//      button.setOnTouchListener((v, e) -> super.onTouchEvent(e));

    }

    private boolean handleEvent(View v, MotionEvent event) {
        //do sth.
        return true;
    }

    void print(IGetData<String> data) {
        String msg = data.get();
        System.out.println(msg);
    }

    interface IGetData<T> {//lambda只能用于单一方法类型匹配

        T get();

//        T getaa(int i);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }


}
